package com.xiaomei.manager.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaomei.manager.web.dto.req.MessageDto;
import com.xiaomei.manager.web.sms.HttpSender;


@Controller
@RequestMapping("/shortMessage")
public class MessageController {
	@RequiresPermissions("shortMessage:edit")
    @RequestMapping(method = RequestMethod.GET)
    public String showCreateForm(Model model) {	        
       // model.addAttribute("exp", new Experience());
       //model.addAttribute("op", "发送");
		model.addAttribute("moblietxt", new MessageDto());
       return "message/edit";
    }
	
	
	@RequestMapping(method = RequestMethod.POST)
	@ResponseBody 
	public String GetValidCode(MessageDto moblietxt,HttpServletRequest request, HttpServletResponse response) {
		String mobile = moblietxt.getMobile();
		String context = moblietxt.getContext();
		
		if(!HttpSender.sendValidCode(mobile, context)) {
			return new String("SMS failure!"); 
		}
		
		return new String("SMS success！");
	}
	
}
